package com.wang.interview.threads.streams;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author: wang
 * @date: 2021/7/25 18:04
 * @description:

 * 题目：
 * 请按照给出数据，找出同时满足以下条件的用户，也即以下条件全部满足；
 * 偶数ID且年龄大于24且用户名转为大写且用户名字母倒叙排序
 * 只输出一个用户名字。

 */
public class Demo01 {
    //不使用流的解法
    /*public static void main(String[] args) {
        User u1 = new User(11, "a", 23);
        User u2 = new User(12, "b", 24);
        User u3 = new User(13, "c", 22);
        User u4 = new User(14, "d", 28);
        User u5 = new User(16, "e", 26);

        ArrayList<User> users = new ArrayList<>(Arrays.asList(u1, u2, u3, u4, u5));
        TreeSet<User> set = new TreeSet<User>((o1,o2)->{
            char[] n1 = o1.getName().toCharArray();
            char[] n2 = o2.getName().toCharArray();
            if (n1.length <= n2.length){
                for (int i = 0; i < n1.length; i++) {
                    if (n1[i] < n2[i]){
                        return 1;
                    }
                }
            }else {
                for (int i = 0; i < n2.length; i++) {
                    if (n1[i] < n2[i]){
                        return 1;
                    }
                }
            }
            return -1;
        });
        for (User user : users) {
            if ( user.getId() % 2 == 0 && user.getAge() > 24 ){
                user.setName(user.getName().toUpperCase());
                set.add(user);
            }
        }
        System.out.println(set.first().getName());
    }*/
    //使用流的解法
    public static void main(String[] args) {
        User u1 = new User(11, "a", 23);
        User u2 = new User(12, "b", 24);
        User u3 = new User(13, "c", 22);
        User u4 = new User(14, "d", 28);
        User u5 = new User(16, "e", 26);
        ArrayList<User> list1 = new ArrayList<>(Arrays.asList(u1, u2, u3, u4, u5));
        list1.stream().filter(u -> u.getId() % 2 == 0 && u.getAge() > 24)
                .map(u -> u.getName().toUpperCase()).sorted(Comparator.reverseOrder())
                .limit(1).forEach(System.out::println);
    }
}

interface A {
    String hh(String a, String b);
}

class M {
    public static String xx (A a,String q, String m){
        return a.hh(q,m);
    }
}

class J{
    public void pri(String a){
        System.out.println(a);
    }

    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 2, 10, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
        for (int i = 0; i < 8; i++) {
            pool.execute((()-> System.out.println(Thread.currentThread().getName()+"开始了")));
        }
        pool.shutdown();
    }
}

class c {
   /* public static void main(String[] args) {
//        System.out.println(M.xx((a,b)->a+b, "a", "b"));
        ArrayList<String> list = new ArrayList<>(Arrays.asList("3", "2", "1"));
//        list.forEach(new J()::pri);
        TreeSet<Integer> set = new TreeSet<>();
        list.stream().sorted().forEach(System.out::print);
    }*/
   public static void main(String[] args) {
//       ArrayList<String> list = new ArrayList<>(Arrays.asList("asdad", "dasd", "daf", "A0", "ccc"));
//       list.stream().sorted(Comparator.reverseOrder()).forEach(System.out::println);
//       list.stream().sorted(Collections.reverseOrder()).forEach(System.out::println);
       ArrayList<Integer> l = new ArrayList<>(Arrays.asList(1, 2, 3, 3));
       l.stream().sorted((a,b)->0).forEach(System.out::println);
   }
}


